﻿using DDDNorthWind.Core.Bus;
using DDDNorthWind.Core.Message;

namespace DDDNorthWind.Core.MessageHandler
{
    public abstract class MessageHandler<TMessage>:IMessageHandler<TMessage> where TMessage : IMessage
    {
        public abstract void Dispose();

        public IBus Bus { get; set; }

        public abstract void Handler(TMessage command);

        protected void SendAsyncMessage<TMessageToSend>(TMessageToSend message) where TMessageToSend:IMessage
        {
            Bus.WithMessage(message).AsAsync().Send();
        }
    }
}